import request from '@/utils/request'
import { CategoryResponseData, AttrResponseData, Attr } from './type'

enum API {
  GETCATEGORY1_URL = '/admin/product/getCategory1',
  GETCATEGORY2_URL = '/admin/product/getCategory2/',
  GETCATEGORY3_URL = '/admin/product/getCategory3/',
  GETATTRINFOLIST_URL = '/admin/product/attrInfoList/',
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  DELETEATTR_URL = '/admin/product/deleteAttr/',
}

export const getCategory1Api = () =>
  request.get<any, CategoryResponseData>(API.GETCATEGORY1_URL)
export const getCategory2Api = (category1Id: number | string) =>
  request.get<any, CategoryResponseData>(API.GETCATEGORY2_URL + category1Id)
export const getCategory3Api = (category2Id: number | string) =>
  request.get<any, CategoryResponseData>(API.GETCATEGORY3_URL + category2Id)
export const getAttrInfoListApi = (
  category1Id: number | string,
  category2Id: number | string,
  category3Id: number | string,
) =>
  request.get<any, AttrResponseData>(
    API.GETATTRINFOLIST_URL + `${category1Id}/${category2Id}/${category3Id}`,
  )
export const addOrUpdateAttrApi = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATEATTR_URL, data)
export const deleteAttrApi = (id: number) =>
  request.delete<any, any>(API.DELETEATTR_URL + id)
